import domain.Student;
import mapper.StudentMapper;
import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

import java.io.IOException;
import java.io.InputStream;
import java.util.List;

public class MapperProxyMain {
    public static void main(String[] args) throws IOException {
        // 1. 定义配置文件的位置
        String resource = "mybatis-config.xml";
        // 2. 获取这个文件的输入流
        InputStream inputStream = Resources.getResourceAsStream(resource);
        // 3. 基于配置文件构建SqlSessionFactory
        SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(inputStream);
        try (
                SqlSession sqlSession = sqlSessionFactory.openSession()
        ) {
            StudentMapper studentMapper = sqlSession.getMapper(StudentMapper.class);
            List<Student> list = studentMapper.selectStudent();
            list.forEach(System.out::println);
        }
    }
}
